<?

/**
 * Description of iChecker.info
 * Version 1.0
 * Release March-15-2013
 * @author CuongNQ
 *  // CODE___ | Message
    // MSG_000 | Success
    // MSG_001 | Couldn't connect to API
    // MSG_002 | No response from API server
    // MSG_003 | API key is invalid
    // MSG_004 | Server is busy
    // MSG_005 | Requested IMEI is not valid
    // MSG_006 | Your credit not enough to check
 */
class ICheckerAPI{

    /**
     * API URL
     */
    const API_URL = "http://ichecker.info/manager/api/";

    /**
     * API Key
     */
    const api_key = '4FD15F50CE173EF4CBC9BC34D55C4720';

    /**
     * Connect method
     * Param: method, params
     */
    private function connect ($method, $params = array()) {
        foreach ($params as $key => $value)
            $up[] = "$key=" . urlencode($value);

        $r = file_get_contents(isset($up)?
                self::API_URL . $method . '?key=' . self::api_key . '&' .
                         implode("&", $up):
                self::API_URL . $method . '?key=' . self::api_key);

        if ($r === false)
            return array(
                    "message_code" => 'MSG_001',
                    "message" => "Couldn't connect to API"
            );

        if (empty($r))
            return array(
                    "message_code" => 'MSG_002',
                    "message" => "No response from API server"
            );
        return json_decode($r, true);
    }

    /**
     * Get information
     */
    public function getInformation () {
        return $this->connect("get-information");
    }

    /**
     * Check hash status
     * Param: imei
     */
    public function check ($imei) {
        return $this->connect("check",
                array(
                        'imei' => $imei
                ));
    }
}
?>